import Vue from "vue";
import VueRouter from "vue-router";

if (process.env.NODE_ENV === "development") {
    Vue.use(VueRouter);
}

import { ROUTER_MODE } from "../config/app";




const err401 = r =>
    require.ensure([], () => r(require("../views/error/err401.vue")), "home");
const err404 = r =>
    require.ensure([], () => r(require("../views/error/err404.vue")), "home");
const login = r =>
    require.ensure([], () => r(require("../views/login/index.vue")), "home");
const main = r =>
    require.ensure([], () => r(require("../views/home/main.vue")), "home");

// 注意 权限字段 authRule （严格区分大小写）
export const constantRouterMap = [
    {
        path: "*",
        component: err404,
        hidden: true
    },
    {
        path: "/401",
        component: err401,
        name: "401",
        hidden: true
    },
    {
        path: "/404",
        component: err404,
        name: "404",
        hidden: true
    },
    {
        path: "/500",
        component: err404,
        name: "500",
        hidden: true
    },
    {
        path: "/login",
        component: login,
        name: "登录",
        hidden: true
    },
    {
        path: "/",
        component: resolve => require(['../views/home/index.vue'], resolve),
        redirect: "/home",
        name: "首页",
        hidden: true
    },
    {
        path: "/home",
        component: resolve => require(['../views/home/index.vue'], resolve),
        redirect: "/home/main",
        icon: "shouye",
        name: "商家后台管理系统",
        noDropdown: true,
        children: [
            {
                path: "main",
                component: main
            }
        ]
    }
];
/*export default new Router({
    mode : 'history',
  base: '/dist/'  //添加的地方
});*/

export default new VueRouter({
    mode: ROUTER_MODE,
    routes: constantRouterMap,
    strict: process.env.NODE_ENV !== "production"
});

var routerMap = [
    {
        path: "/vipManage",
        redirect: "user",
        component: resolve => require(['../views/home/index.vue'], resolve),
        icon: "ziyuanjiaoseguanli",
        name: "VIP管理",
        meta: {
            authRule: ["vipManage"]
        },
        children: [
            {
                path: "user",
                component: resolve => require(['../views/vipManage/user'], resolve),
                name: "VIP账户管理",
                meta: {
                    authRule: ["vipManage/user"]
                }
            },
            {
                path: "VIP",
                component: resolve => require(['../views/vipManage/VIP'], resolve),
                name: "VIP",
                hidden: true
                // meta: {
                //     authRule: ["vipManage/VIP"]
                // }
            }
        ]
    },

    {
        path: "/merchant",
        redirect: "mycommodity",
        component: resolve => require(['../views/home/index.vue'], resolve),
        icon: "dingdan",
        name: "商品管理",
        meta: {
            authRule: ["merchantsCommodity"]
        },
        noDropdown: false,
        children: [
            {
                path: "mycommodity",
                component: resolve => require(['../views/commodity/commodity.vue'], resolve),
                name: "我的商品",
                meta: {
                    authRule: ["merchantsCommodity/myCommodity"]
                }
            },
            {
                path: "platformCommodity",
                component: resolve => require(['../views/commodity/platformCommodity.vue'], resolve),
                name: "平台商品",
                meta: {
                    authRule: ["merchantsCommodity/platformCommodity"]
                }
            },
            {
                path: "comment",
                component: resolve => require(['../views/commodity/comment.vue'], resolve),
                name: "评论",
                hidden: true
            },
            {
                path: "otherBrandCommodity",
                component: resolve => require(['../views/commodity/otherBrandCommodity'], resolve),
                name: "其他品牌",
                meta: {
                    authRule: ["merchantsCommodity/otherBrandCommodity"]
                }
            },
            {
                path: "brandCommodity",
                component: resolve => require(['../views/commodity/brandCommodity.vue'], resolve),
                name: "隶属品牌商品",
                meta: {
                    authRule: ["merchantsCommodity/brandCommodity"]
                }
            },
            {
                path: "brandAgentCommodity",
                component: resolve => require(['../views/commodity/brandAgentCommodity.vue'], resolve),
                name: "品牌代理商商品",
                meta: {
                    authRule: ["merchantsCommodity/brandAgentCommodity"]
                }
            },
            {
                path: "brandAuditAgentCommodity",
                component: resolve => require(['../views/commodity/brandAuditAgentCommodity.vue'], resolve),
                name: "申请品牌代理商商品",
                meta: {
                    authRule: ["merchantsCommodity/brandAuditAgentCommodity"]
                }
            },
            {
                path: "addBrandAgentCommodity",
                component: resolve => require(['../views/commodity/addBrandAgentCommodity.vue'], resolve),
                name: "我的商品",
                hidden: true,
                meta: {
                    authRule: ["merchantsCommodity/brandAgentCommodity"]
                }
            }
        ]
    },
    {
        path: "/myBusiness",
        redirect: "signAgreement",
        component: resolve => require(['../views/home/index.vue'], resolve),
        icon: "ic_opt_feature",
        name: "我的商家",
        meta: {
            authRule: ["myBusiness"]
        },
        noDropdown: false,
        children: [
            {
                path: "signAgreement",
                component: resolve => require(['../views/myBusiness/signAgreement.vue'], resolve),
                name: "签订入驻协议",
                meta: {
                    authRule: ["myBusiness/signAgreement"]
                }
            },
            {
                path: "myApplication",
                component: resolve => require(['../views/myBusiness/myApplication.vue'], resolve),
                name: "我的申请",
                meta: {
                    authRule: ["myBusiness/myApplication"]
                }
            },
            {
                path: "setComRule",
                component: resolve => require(['../views/myBusiness/setComRule.vue'], resolve),
                name: "商家规则设置",
                meta: {
                    authRule: ["myBusiness/setComRule"]
                }
            }
        ]
    },
    {
        path: "/merchantsMergedCompany",
        redirect: "promotionApplication",
        component: resolve => require(['../views/home/index.vue'], resolve),
        icon: "jixianguanli",
        name: "合伙公司管理",
        meta: {
            authRule: ["merchantsMergedCompany"]
        },
        children: [
            {
                path: "promotionApplication",
                component: resolve => require(['../views/merchantsMergedCompany/promotionApplication.vue'], resolve),
                name: "晋升申请管理",
                meta: {
                    authRule: ["merchantsMergedCompany/promotionApplication"]
                }
            },
            {
                path: "cooperation",
                component: resolve => require(['../views/merchantsMergedCompany/incubationTeam.vue'], resolve),
                name: "协作管理",
                meta: {
                    authRule: ["merchantsMergedCompany/cooperation"]
                }
            }
        ]
    },
    // {
    //     path: "/purchaseManagement",
    //     redirect: purchaseManagement,
    //     component: resolve => require(['../views/home/index.vue'],resolve),
    //     icon: "yaofang",
    //     name: "仓库管理",
    //     meta: {
    //         authRule: ["purchaseManagement"]
    //     },
    //     children: [
    //         {
    //             path: "purchaseManagement",
    //             component: resolve => require(['../views/purchaseManagement/purchaseManagement.vue'],resolve),
    //             name: "进货管理",
    //             meta: {
    //                 authRule: ["purchaseManagement/purchaseManagement"]
    //             }
    //         },
    //         {
    //             path: "deliveryManagement",
    //             component: resolve => require(['../views/purchaseManagement/deliveryManagement.vue'],resolve),
    //             name: "提货管理",
    //             meta: {
    //                 authRule: ["purchaseManagement/deliveryManagement"]
    //             }
    //         }
    //     ]
    // },
    {
        path: "/myCompany",
        redirect: "myCompany",
        component: resolve => require(['../views/home/index.vue'], resolve),
        icon: "caiwu",
        name: "我的公司",
        meta: {
            authRule: ["myCompany"]
        },
        children: [
            {
                path: "myCompany",
                component: resolve => require(['../views/myCompany/myCompany/index.vue'], resolve),
                name: "我的公司",
                meta: {
                    authRule: ["myCompany/myCompany"]
                }
            },
            {
                path: "partnerChange",
                component: resolve => require(['../views/myCompany/myCompany/partnerChange.vue'], resolve),
                name: "首席合伙人变更",
                hidden: true,
                meta: {
                    authRule: ["myCompany/myCompany"]
                }
            },
            {
                path: "subordinate",
                component: resolve => require(['../views/myCompany/subordinate.vue'], resolve),
                name: "被服务商城",
                meta: {
                    authRule: ["myCompany/Subordinate"]
                }
            },
            // {
            //     path: "companyManage",
            //     component: resolve => require(['../views/myCompany/companyManage'],resolve),
            //     name: "公司管理",
            //     meta: {
            //         authRule: ["myCompany/companyManage"]
            //     }
            // },
            {
                path: "createCompanyWill",
                component: resolve => require(['../views/myCompany/createCompanyWill.vue'], resolve),
                name: "组建公司意愿管理",
                meta: {
                    authRule: ["myCompany/myCompany"]
                }
            }
        ]
    },
    {
        path: "/merchantOrder",
        redirect: "purchaseOrder",
        component: resolve => require(['../views/home/index.vue'], resolve),
        icon: "jixianguanli",
        name: "订单管理",
        meta: {
            authRule: ["merchantOrder"]
        },
        children: [
            {
                path: "purchaseOrder",
                component: resolve => require(['../views/commodity/purchaseOrder.vue'], resolve),
                name: "进货订单",
                meta: {
                    authRule: ["merchantOrder/purchaseOrder"]
                }
            },
            {
                path: "saleOrder",
                component: resolve => require(['../views/commodity/saleOrder.vue'], resolve),
                name: "销售订单",
                meta: {
                    authRule: ["merchantOrder/saleOrder"]
                }
            },

            {
                path: "retailOrder",
                component: resolve => require(['../views/commodity/retailOrder'], resolve),
                name: "零售订单",
                meta: {
                    authRule: ["merchantOrder/retailOrder"]
                }
            },
            {
                path: "retaildetail",
                component: resolve => require(['../views/commodity/retaildetail'], resolve),
                name: "零售订单详情",
                hidden: true
            },
            {
                path: "distributionRetailOrder",
                component: resolve => require(['../views/commodity/distributionRetailOrder'], resolve),
                name: "分销零售订单",
                meta: {
                    authRule: ["merchantOrder/distributionRetailOrder"]
                }
            },
            {
                path: "distributionorderdetail",
                component: resolve => require(['../views/commodity/distributionorderdetail'], resolve),
                name: "分销订单详情",
                hidden: true
            },
            {
                path: "distributuionVip",
                component: resolve => require(['../views/commodity/distributuionVip'], resolve),
                name: "分销订单（VIP）",
                meta: {
                    authRule: ["merchantOrder/distributuionVip"]
                }
            }
        ]
    },
    /*订单详细*/
    {
        path: "/statistics/orderdetail",
        redirect: "/statistics/orderdetail",
        component: resolve => require(['../views/home/index.vue'], resolve),
        name: "订单详细",
        hidden: true,
        children: [
            {
                path: "",
                component: resolve => require(['@/views/statistics/orderdetail'], resolve)
            }
        ]
    },

    {
        path: "/merchantOrder/purchaseOrderDetail",
        redirect: "/merchantOrder/purchaseOrderDetail",
        component: resolve => require(['../views/home/index.vue'], resolve),
        name: "进货订单详细",
        hidden: true,
        children: [
            {
                path: "",
                component: resolve => require(['../views/commodity/purchaseOrderDetail.vue'], resolve)
            }
        ]
    },

    {
        path: "/userManage",
        redirect: "userManage/authAdmin",
        component: resolve => require(['../views/home/index.vue'], resolve),
        icon: "ic_opt_feature",
        name: "权限管理",
        meta: {
            authRule: ["user_manage"]
        },
        children: [
            {
                path: "authAdmin",
                component: resolve => require(['../views/userManage/admin/authAdmin.vue'], resolve),
                name: "管理员管理",
                meta: {
                    authRule: ["admin/auth/admin/index"]
                }
            },
            {
                path: "authRole",
                component: resolve => require(['../views/userManage/admin/authRole.vue'], resolve),
                name: "角色管理",
                meta: {
                    authRule: ["admin/auth/role/index"]
                }
            }
        ]
    },

    {
        path: "/fundsManagement",
        redirect: "fundsManagement/fundsDetail",
        component: resolve => require(['../views/home/index.vue'], resolve),
        icon: "baobiaoguanli",
        name: "商家资金管理",
        meta: {
            authRule: ["fundsManagement"]
        },
        children: [
            {
                path: "fundsDetail",
                component: resolve => require(['../views/fundsManagement/fundsDetail'], resolve),
                name: "资金明细",
                meta: {
                    authRule: ["fundsManagement/fundsDetail"]
                }
            },
            {
                path: "fundsManage",
                component: resolve => require(['../views/fundsManagement/fundsManage'], resolve),
                name: "资金申请",
                meta: {
                    authRule: ["fundsManagement/fundsManage"]
                }
            }
        ]
    },

];
export const asyncRouterMap = routerMap;
